package com.bootdo.dev.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.common.annotation.Log;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.dev.domain.PhoneDev;
import com.bootdo.dev.service.impl.PhoneDevService;
import com.bootdo.system.domain.RoleDO;
import com.bootdo.system.domain.UserDO;

@RequestMapping("/dev")
@Controller
public class PhoneDevController 
{
	private final Logger logger = LoggerFactory.getLogger(PhoneDevController.class);
	
	@Resource
    private PhoneDevService  phoneDevService;

	@GetMapping("/list")
	public String toListPage() 
	{
		return "/dev/phone/phoneDev";
	}
	
	@RequiresPermissions("dev:update")
	@Log("编辑手机设备")
	@GetMapping("/edit/{id}")
	String edit(Model model, @PathVariable("id") Long id) {
		PhoneDev phoneDev = phoneDevService.getPhoneDevById(id);
		model.addAttribute("phoneDev", phoneDev);
		return "/dev/phone/edit";
	}
	
	
	@ResponseBody
	@RequiresPermissions("dev:delete")
	@GetMapping("/getList")
	public PageUtils getDevList(@RequestParam Map<String, Object> params) 
	{
		// 查询列表数据
		Query query = new Query(params);
		List<PhoneDev> bContentList = phoneDevService.list(query);
		int total = phoneDevService.count(query);
		PageUtils pageUtils = new PageUtils(bContentList, total);
		return pageUtils;
	}
	
	@ResponseBody
	@RequiresPermissions("dev:delete")
	@PostMapping("/update")
	public R getDevList(PhoneDev phoneDev) 
	{
		if(null == phoneDev || phoneDev.getId() == null || phoneDev.getId()<=0)
		{
			logger.info("=======phoneDev={}",phoneDev);
			return R.error("数据异常");
		}
		logger.info("=====phoneDev={}",phoneDev);
		phoneDevService.updatePhoneById(phoneDev);
		return R.ok();
	}
	
}
